package com.otachn.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.otachn.jdbc.DBLink;
import com.otachn.utiils.InformationEntity;
import com.otachn.utiils.Role;

/**
 * Servlet implementation class ServletUpdateCertificate
 */
//@WebServlet("/ServletUpdateCertificate")
public class ServletUpdateCertificate extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletUpdateCertificate() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Role role = DBLink.getRoleEntity(request.getParameter("username"),request.getParameter("password") );
		if (role.getId() == 0) {
			request.getRequestDispatcher("index.html").forward(request, response);
		}
		else {
			request.getRequestDispatcher("/WEB-INF/resultupdate.jsp").forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String xm = request.getParameter("xm");
		String xb = request.getParameter("xb");
		String sfzh = request.getParameter("sfzh");
		String csrq = request.getParameter("csrq");
		String zsbh = request.getParameter("zsbh");
		String zy = request.getParameter("zy");
		String bzrq = request.getParameter("bzrq");
		String llcj = request.getParameter("llcj");
		String czcj = request.getParameter("czcj");
		String pdcj = request.getParameter("pdcj");
		String pxdw = request.getParameter("pxdw");
		String fzdw = request.getParameter("fzdw");
		
		InformationEntity ie = new InformationEntity();
		ie.setXm(xm);
		ie.setXb(xb);
		ie.setSfzh(sfzh);
		ie.setCsrq(csrq);
		ie.setZsbh(zsbh);
		ie.setZy(zy);
		ie.setBzrq(bzrq);
		ie.setLlcj(Integer.valueOf(llcj));
		ie.setCzcj(Integer.valueOf(czcj));
		ie.setPdcj(pdcj);
		ie.setPxdw(pxdw);
		ie.setFzdw(fzdw);
		
		boolean success = DBLink.InsertIntoInformation(ie);
		if (success) {
			request.setAttribute("errmessage", "添加成功！");
		}
		else {
			request.setAttribute("errmessage", "添加失败！");
		}
		request.getRequestDispatcher("/WEB-INF/resultupdate.jsp").forward(request, response);
		
	}

}
